import { Injectable } from '@nestjs/common';
import { CreateRoleDto } from './dto/create-role.dto';
import { UpdateRoleDto } from './dto/update-role.dto';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class RoleService {
  constructor(private prisma: PrismaClient) {}
  create(createRoleDto: CreateRoleDto) {
    const { menu, ...role } = createRoleDto;
    return this.prisma.role.create({
      data: {
        ...role,
        menu: {
          create: menu,
        },
      },
    });
  }

  find() {
    return `This action returns all role`;
  }

  findOne(id: number) {
    return this.prisma.role.findUnique({ where: { id } });
  }

  update(id: number, updateRoleDto: UpdateRoleDto) {
    const { menu, ...role } = updateRoleDto;
    return this.prisma.role.update({
      where: { id },
      data: {
        ...role,
        menu: {
          update: menu,
        },
      },
    });
  }

  remove(id: number) {
    return this.prisma.role.delete({ where: { id } });
  }
}
